//axios 工具函数
import store from '@/store'
import axios from 'axios'

//封装 默认地址&超时时间
const instance = axios.create({
  baseURL: 'http://sell.h5.itsource.cn:8087',
  timeout: 10000,
})
//封装请求拦截器 携带统一参数
instance.interceptors.request.use(
  config => {
    //获取token
    const token = store.getters.token
    //携带token
    token && (config.headers.authorization = token)
    return config
  },
  err => {
    return Promise.reject(err)
  }
)
//封装响应拦截器 处理状态码
instance.interceptors.response.use(
  response => {
    return response
  },
  err => {
    return Promise.reject(err)
  }
)

//导出封装好的axios 实例
export default instance
